<?php
/**
 * 脚本文件输出
 *
 * PHP version 5
 *
 * @package   Ecga
 * @author    sunfengming <sunfengming@ec3s.com>
 * @copyright 2011 Xingchangxinda Inc.
 * @version   SVN: $Id$
 */
namespace Project\Apps\Ecga\Library;

use \Framework\System\Helper\HttpRequest;
use \Framework\System\Helper\HttpResponse;

/**
 * 脚本文件输出
 *
 * @package   Ecga
 * @author	  sunfengming <sunfengming@ec3s.com>
 * @copyright 2011 Xingchangxinda Ltd.
 * @version   Release: v0.1
 */
class JsFileResponse extends HttpResponse
{
	/**
	 * 将多个文件合并包括扩展内容后输出
	 * 
	 * @param array  $fileNames   文件名称及地址
	 * @param string $andContents 扩展内容
	 * @param string $contentType 文件头contentType
	 * 
	 * @return void
	 * @author sunfengming
	 */
	static public function outputJsFiles($fileNames, $andContents = '', $contentType = 'text/javascript')
	{
		$contents = '';
		foreach ($fileNames as $fileName) {
			
			if (!is_file($fileName)) {
	            throw new Exception("文件不存在");
	        }
	        $handle = fopen($fileName, "r");
	        $contents .= fread($handle, filesize($fileName));
	        fclose($handle);
		}
		$contents .= "\n" . $andContents;
		parent::output($contents, $contentType);
	}
}